package com.ckd.flyingtrip.charge.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.ckd.flyingtrip.R;
import com.ckd.flyingtrip.charge.javabean.ChargeOrderBean;
import com.ckd.flyingtrip.javabean.OrderBean;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;

public class ChargeOrderAdapter extends RecyclerView.Adapter<ChargeOrderAdapter.MyHolder> {

    private Context context;
    private List<ChargeOrderBean.DataBean.ListBean> list;
    public OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onClick(View view, int position);
    }

    public ChargeOrderAdapter(Context context, List<ChargeOrderBean.DataBean.ListBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MyHolder(LayoutInflater.from(context).inflate(R.layout.item_charge_order_1, null));
    }

    @Override
    public void onBindViewHolder(@NonNull MyHolder holder, int position) {
        holder.orderId.setText(list.get(position).getOrderId());
        if ("0".equals(list.get(position).getBatteryType())){
            holder.type.setText("磷酸铁锂电池");
        }else if ("1".equals(list.get(position).getBatteryType())){
            holder.type.setText("铅酸电池");
        }

        holder.voltage.setText(list.get(position).getBatteryVoltage() + "V");
        holder.time.setText(list.get(position).getBatteryTime() + "小时");
//        holder.money.setText(list.get(position).get);

//        int Days = list.get(position).getOrderBuyDays().equals("") ? 0 : Integer.parseInt(list.get(position).getOrderBuyDays());
//        String endTime = getOldDateByDay(parseServerTime(list.get(position).getOrderPayTime(), "yyyy-MM-dd HH:mm:ss"), Days, "yyyy.MM.dd");
//        holder.ll1_textView3.setText(list.get(position).getOrderPayTime().substring(0, 4) + "." + list.get(position).getOrderPayTime().substring(5, 7) + "." +
//                list.get(position).getOrderPayTime().substring(8, 10) + "-" + endTime);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public class MyHolder extends RecyclerView.ViewHolder {
        TextView orderId, type, voltage, time, money;

        public MyHolder(@NonNull View itemView) {
            super(itemView);
            orderId = itemView.findViewById(R.id.item_battery_orderId);
            type = itemView.findViewById(R.id.item_battery_type);
            voltage = itemView.findViewById(R.id.item_battery_voltage);
            time = itemView.findViewById(R.id.item_battery_time);
            money = itemView.findViewById(R.id.item_battery_money);


        }
    }

//    private Date parseServerTime(String serverTime, String format) {
//        if (format == null || format.isEmpty()) {
//            format = "yyyy-MM-dd HH:mm:ss";
//        }
//        SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.CHINESE);
//        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
//        Date date = null;
//        try {
//            date = sdf.parse(serverTime);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return date;
//    }
//
//
//    private String getOldDateByDay(Date beginDate, int distanceDay, String format) {
//        if (format == null || format.isEmpty()) {
//            format = "yyyy-MM-dd";
//        }
//        SimpleDateFormat dft = new SimpleDateFormat(format);
//        Calendar date = Calendar.getInstance();
//        date.setTime(beginDate);
//        date.set(Calendar.DATE, date.get(Calendar.DATE) + distanceDay);
//        Date endDate = null;
//        try {
//            endDate = dft.parse(dft.format(date.getTime()));
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return dft.format(endDate);
//    }

}
